
#include <BStyle>
#include "member_BGroupItem.h"
#include "member_BGraphicWidget.h"
#include "member_BGraphicItem.h"
#include "IGlobal.h"

using namespace BWE;

member_BGroupItem::member_BGroupItem(BGroupItem* labelItem)
{
	boss = labelItem;
	flat = false;
	wired = true;
	titleVisible = true;
	folded = false;
	checkable = false;
	checked = false;
	ia_align = Align_LeftCenter;
	ia_spacing = 2;
	wireSize = 1.0f;
	dirty = false;
	state = State_Normal;
	dirty = true;
}
member_BGroupItem::~member_BGroupItem()
{

}

void member_BGroupItem::freshRects(const BStyle* style)
{
	if (style)
		style->translate(boss->title(), t_title);
	else
		t_title.clear();

	BSizef textSize;
	if (const BFont* font = style->font())
	{
		if (t_title.size())
			textSize = font->textSize(t_title);
		else
			textSize = font->textSize(boss->title());
	}

	BRectf titleRect = boss->rect(Part_Top);
	titleRect.top() += titleMargin.top();
	titleRect.left() += titleMargin.left();
	titleRect.right() -= titleMargin.right();
	titleRect.bottom() -= titleMargin.bottom();

	ia_iconSize.reset();
	if (icon || ia_form > Form_TextOnly || checkable)
	{
		ia_iconSize = iconSize;
		if (ia_iconSize.width() < 1)
			ia_iconSize.width() = textSize.height();
		if (ia_iconSize.height() < 1)
			ia_iconSize.height() = textSize.height();
	}
	ia_textSize = textSize;
	titleArea = adjust(titleRect);

	float border = boss->border();
	BSizef size = boss->rect().size();
	BPerchf perch = boss->perch();

	BRectf wireRect;
	wireRect.left() = border + perch.left() / 2.0f;
	wireRect.top() = border + perch.top() / 2.0f;
	wireRect.right() = size.width() - border - perch.right() / 2.0f;
	wireRect.bottom() = size.height() - border - perch.bottom() / 2.0f;
	if (item_member(boss)->round)
	{
		wirePoints.reset();
		wirePoints.append(BPointf((float)titleArea.right(), wireRect.top()));
		item_member(boss)->round->createRightTopPoints(wireRect, wirePoints);
		item_member(boss)->round->createRightBottomPoints(wireRect, wirePoints);
		item_member(boss)->round->createLeftBottomPoints(wireRect, wirePoints);
		item_member(boss)->round->createLeftTopPoints(wireRect, wirePoints);
		wirePoints.append(BPointf((float)titleArea.left(), wireRect.top()));
	}
	else
	{
		wirePoints.reset();
		wirePoints.append(BPointf((float)titleArea.left(), wireRect.top()));
		wirePoints.append(wireRect.leftTop());
		wirePoints.append(wireRect.leftBottom());
		wirePoints.append(wireRect.rightBottom());
		wirePoints.append(wireRect.rightTop());
		wirePoints.append(BPointf((float)titleArea.right(), wireRect.top()));
	}
}
